/**	\file		lxsamsara_main.cpp
 *	\date		(2014-12-28 22:49:38)/(2014-12-28 22:49:38)
 *-----------------------------------------------------------------------------
 *	\brief
 *	\version	1.0.0.1
 *	\author		Nick Shallery	(nicknide@gmail.com)
 *	\copyright	YOU HAVE ALL LEFT WITH THIS CODE WHILE YOU KEEP COMMENT IN EVERY COPY.
 *-----------------------------------------------------------------------------
**/

#include	<lolix/imp/lolix_plugin_auto_release_lib.inl>
#include	<lolix/imp/lolix_plugin_enter.inl>

#include	"./recurrence.h"

lolix::LOLIX_RETNV CreateRecurrenceInst(
	lxsamsara::recurrence** out_ptr
	, lolix::dynamic_allocator* alc
	, lolix::ref_factory* ref_fac);


extern "C" lolix::LOLIX_RETNV	LOLIX_CALL lxpLoading(lolix::lolix_inst* lx_inst, lolix::lolix_regist* lx_reg)
{
	lolix::LOLIX_RETNV rtv;
	lolix::dynamic_allocator* alc;
	if ( LOLIX_CHECK_ERROR(rtv = lx_reg->query_itf(&alc)) )
		return rtv;
	atexit_release(*alc);
	lolix::ref_factory* ref_fac;
	if ( LOLIX_CHECK_ERROR(rtv = lx_reg->query_itf(&ref_fac)) )
		return rtv;
	atexit_release(*ref_fac);

	lxsamsara::recurrence* recur;
	if ( LOLIX_CHECK_ERROR(rtv = CreateRecurrenceInst(&recur, alc, ref_fac)) )
		return rtv;
	atexit_release(*recur);

	if ( LOLIX_CHECK_ERROR(rtv = lx_reg->reg_loli(recur)) )
		return rtv;
	//TODO: add more init code here
	return rtv;
}


extern "C" lolix::LOLIX_RETNV	LOLIX_CALL lxpFreeing(lolix::lolix_inst* lx_inst)
{

	return lolix::imp::plugin_auto_release_lib_query(lx_inst);
}

#if			0
static lolix::LOLIX_RETNV process_enter(void)
{
	return lolix::LOLIX_RETNV_OK;
}

static void process_leave(void)
{
}

static void thread_enter(void)
{
}

static void thread_leave(void)
{
}

#else	//	0
#define	process_enter	0
#define	process_leave	0
#define	thread_enter	0
#define	thread_leave	0
#endif	//	0

#define		lxsamsara_LIB_ID	0xfb6835b1, 0x7854432e, 0xad6a9bd6, 0x38b4a754
LOLIX_DEF__PLUGIN_ENTER(lxsamsara_LIB_ID, "lxsamsara"
	, process_enter, process_leave, thread_enter, thread_leave);
